package com.azi.baseconhecimento.util;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.web.servlet.View;

@SuppressWarnings("unchecked")
public class JsonView implements View {
	
	private static final String DEFAULT_JSON_CONTENT_TYPE = "application/json";
	
	public String getContentType() {
		return DEFAULT_JSON_CONTENT_TYPE;
	}

	public void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		response.setContentType( DEFAULT_JSON_CONTENT_TYPE );
		JSONObject json = JSONObject.fromObject(model);
		response.getWriter().write(json.toString());
		response.setStatus(HttpServletResponse.SC_OK);
		response.getWriter().flush();
		response.getWriter().close();
		

	}

}
